package com.xyc.servlet.main;

import com.xyc.mapper.SongListMapper;
import com.xyc.mapper.SongMapper;
import com.xyc.pojo.Song;
import com.xyc.pojo.SongList;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/myList")
public class MyListServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        //查找歌单 将歌单名发送到 session
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        SongListMapper mapper = ctx.getBean("songListMapper", SongListMapper.class);

        List<SongList> li = mapper.selectSongList();
        HttpSession session = req.getSession();
        session.setAttribute("songList2", li);

        req.getRequestDispatcher("user/myList.jsp").forward(req, resp);
    }
}
